{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "a9dd5e56",
   "metadata": {},
   "source": [
    "# K-means 聚类算法(K-means Clustering Algorithm)\n",
    "\n",
    "        通过计算样本间的距离来判断它们的相近关系。\n",
    "        \n",
    "**聚类与分类最大的区别在于，分类的目标类别是已知的，而聚类的目标类别是未知的。**\n",
    "        \n",
    "        所谓聚类，即根据相似性原则，将具有高相似度的数据划分至同一类簇，将具有高相异度的数据对象划分至不同类簇。\n",
    "        \n",
    "**聚类**为无监督学习，即待处理数据对象没有任何先验知识。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ba2964b6",
   "metadata": {},
   "source": [
    "### K - 平均聚类的目的：\n",
    "        把 n 个点划分到 K 个聚类中，使得每个点都属于离它最近的均值（此即为聚类中心）对应的聚类，以之作为聚类的标准。\n",
    "        K 是用户指定的，每一个簇通过其 质心（Centroid），即簇中所有点的中心来描述。\n",
    "        \n",
    "<img src='img/1.jpg' width='600px' />\n",
    "<img src='img/2.jpg' width='600px' />\n",
    "<img src='img/3.jpg' width='600px' />\n",
    "\n",
    "**7.当所有的点无法再更新到其他分类时，算法结束，此时继续迭代，聚类中心也不会再发生改变**"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c619f5c3",
   "metadata": {},
   "source": [
    "<br>\n",
    "\n",
    "***\n",
    "\n",
    "<br>\n",
    "\n",
    "K-means 算法通常采用欧氏距离来计算数据对象间的距离。对于“噪声”和孤立点数据是敏感的。\n",
    "\n",
    "* 终止条件：\n",
    "    * A---> 没有（或最小数目）对象被重新分配给不同的聚类\n",
    "    * B---> 没有（或最小数目）聚类中心再发生变化\n",
    "    * C---> 误差平方和局部最小\n",
    "    "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "58f38aea",
   "metadata": {},
   "source": [
    "## K-means 优缺点\n",
    "【优点】\n",
    "1. 属于无监督学习，无须准备训练集\n",
    "\n",
    "\n",
    "2. 原理简单，实现起来较为容易\n",
    "\n",
    "\n",
    "3. 结果可解释性好\n",
    "\n",
    "【缺点】\n",
    "1. 聚类数目 K 是一个输入参数，选择不恰当的 K 值可能会导致糟糕的聚类结果。\n",
    "    * 这也是为什么要进行`特征检验`来决定数据集的聚类数目。\n",
    "\n",
    "\n",
    "2. 在大规模数据集上收敛比较慢\n",
    "\n",
    "\n",
    "3. 对于异常点和离群点比较敏感\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "41293fd5",
   "metadata": {},
   "source": [
    "## K-means 应用场景\n",
    "\n",
    "聚类用于数据集内**种类属性不明晰**、**希望能够通过数据挖掘出自动归类出有相似对象**的场景。\n",
    "\n",
    "其商业界的应用场景一般为挖掘出具有相似特点的潜在客户群体，以便公司能够重点研究、对症下药。\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "72a503b3",
   "metadata": {},
   "source": [
    "# K-means 聚类算法实现鸢尾花数据的聚类"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "6f4e0638",
   "metadata": {},
   "outputs": [],
   "source": [
    "import warnings\n",
    "warnings.filterwarnings('ignore')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "ac81aba9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(150, 2)\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYIAAAEGCAYAAABo25JHAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAhRElEQVR4nO3dfXAc9Z3n8ffXI+lAiVlnsWqDbSyRFFCx2bXBOgcIT4nN8eTdXF0SLjlzu5CkdJFCDiqX2gSoDReuXLfZP1K7AYTjDQYn1gHBsIHjTLIkB3s8BBaZNQ/GwJFgg9a+IFjAEPNgy9/7o1tYGvXM9ExPz/RMf15VXZr5TT98B8r6qvv3+/5+5u6IiEh+zWp2ACIi0lxKBCIiOadEICKSc0oEIiI5p0QgIpJzHc0OoFpz5871vr6+ZochItJStmzZ8oq790R91nKJoK+vj9HR0WaHISLSUsxsZ6nP9GhIRCTnlAhERHJOiUBEJOdaro8gyr59+xgbG+Odd95pdih1c8ghh7BgwQI6OzubHYqItLm2SARjY2PMnj2bvr4+zKzZ4STm7rz66quMjY1x1FFHNTscEWlzqT0aMrMjzexeM9tuZtvM7JKIfc4wszfMbGu4fbuWa73zzjscfvjhbZEEAMyMww8/vK3ucETqYmQE+vpg1qzg58hI8mOTnLNNpHlHsB/4L+7+mJnNBraY2T3u/nTRfve7+6qkF2uXJDCp3b6PSGIjIzAwAHv3Bu937gzeA6xeXduxDz4IGzbUds42ktodgbvvdvfHwtdvAtuB+WldT0Ta3BVXHPyFPWnv3qC91mPXrav9nG2kIaOGzKwPOB54JOLjk8zscTO728wWlzh+wMxGzWx0fHw8zVBFJKtefLG69jj7TEzUfs42knoiMLMPArcBl7r7nqKPHwN63X0JcDXw06hzuPs6d+939/6ensgKaRFpdwsXVtceZ59CofZztpFUE4GZdRIkgRF3v734c3ff4+5vha83A51mNjfNmIBUOod+97vfcd5557FkyRKOO+44brnlFrZs2cLpp5/OsmXLOOuss9i9ezcAv/71rzn77LNZtmwZp556Ks8880zi64u0vTVroLt7elt3d9Be67EDA7Wfs524eyobYMCPgL8us8+HAQtfLwdenHxfalu2bJkXe/rpp2e0lbRxo3t3tzsc3Lq7g/YENm3a5F/+8pfff//666/7SSed5C+//LK7u998881+0UUXubv7pz71KX/uuefc3f3hhx/2T37yk5HnrOp7ieTBxo3uvb3uZsHPav7dljo2yTlbCDDqJX6vTv4SrjszOwW4H3gSOBA2Xw4sDBPQWjO7GBgkGGH0NvB1d3+o3Hn7+/u9eNK57du387GPfSxeYH19wciAYr29sGNHvHNEeO655zjrrLM4//zzWbVqFR/60Ic4+eST+chHPgLAxMQERxxxBLfffjs9PT0ce+yx7x/77rvvsn379hnnrOp7iYiUYWZb3L0/6rP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9KuFk5Zj/YLBEtgPgv0TLabWaeZLQ73eROYHb6e/KX/SrjmQzWjgcpdo5QHgPPD/RcBfzjls33h4yaR1CgRSLvaDvxZ+Jjl9wkWI3mP4Jf6d83scWArcHK4/43A2nA213eBvwWeBH4KPBr3ohWuUcowQfJ4Avgm8ATwRvjZOuCJKZ3FInWn2Uel7YTLd94VdvRmXjgFd6e7v2NmHwV+CRwTJhWR1KmPQKT5uoF7w0dABgwqCUgj6Y5ARCTn1EcgIpJzSgQiIjmnRCAiknNKBCIiOadEICKSc/8fD/Sm+jciI6sAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt  \n",
    "import numpy as np  \n",
    "from sklearn.cluster import KMeans\n",
    "from sklearn import datasets\n",
    "from sklearn.datasets import load_iris\n",
    "iris=load_iris()\n",
    "X = iris.data[:,2:4] ##表示我们只取特征空间中的后两个维度\n",
    "print(X.shape)\n",
    "#绘制数据分布图\n",
    "plt.scatter(X[:, 0], X[:, 1], c = \"red\", marker='o', label='see')  \n",
    "plt.xlabel('petal length')  \n",
    "plt.ylabel('petal width')  \n",
    "plt.legend(loc=2)  \n",
    "plt.show()  \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "5fa68fdb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1.4, 0.2],\n",
       "       [1.4, 0.2],\n",
       "       [1.3, 0.2],\n",
       "       [1.5, 0.2],\n",
       "       [1.4, 0.2],\n",
       "       [1.7, 0.4],\n",
       "       [1.4, 0.3],\n",
       "       [1.5, 0.2],\n",
       "       [1.4, 0.2],\n",
       "       [1.5, 0.1],\n",
       "       [1.5, 0.2],\n",
       "       [1.6, 0.2],\n",
       "       [1.4, 0.1],\n",
       "       [1.1, 0.1],\n",
       "       [1.2, 0.2],\n",
       "       [1.5, 0.4],\n",
       "       [1.3, 0.4],\n",
       "       [1.4, 0.3],\n",
       "       [1.7, 0.3],\n",
       "       [1.5, 0.3],\n",
       "       [1.7, 0.2],\n",
       "       [1.5, 0.4],\n",
       "       [1. , 0.2],\n",
       "       [1.7, 0.5],\n",
       "       [1.9, 0.2],\n",
       "       [1.6, 0.2],\n",
       "       [1.6, 0.4],\n",
       "       [1.5, 0.2],\n",
       "       [1.4, 0.2],\n",
       "       [1.6, 0.2],\n",
       "       [1.6, 0.2],\n",
       "       [1.5, 0.4],\n",
       "       [1.5, 0.1],\n",
       "       [1.4, 0.2],\n",
       "       [1.5, 0.2],\n",
       "       [1.2, 0.2],\n",
       "       [1.3, 0.2],\n",
       "       [1.4, 0.1],\n",
       "       [1.3, 0.2],\n",
       "       [1.5, 0.2],\n",
       "       [1.3, 0.3],\n",
       "       [1.3, 0.3],\n",
       "       [1.3, 0.2],\n",
       "       [1.6, 0.6],\n",
       "       [1.9, 0.4],\n",
       "       [1.4, 0.3],\n",
       "       [1.6, 0.2],\n",
       "       [1.4, 0.2],\n",
       "       [1.5, 0.2],\n",
       "       [1.4, 0.2],\n",
       "       [4.7, 1.4],\n",
       "       [4.5, 1.5],\n",
       "       [4.9, 1.5],\n",
       "       [4. , 1.3],\n",
       "       [4.6, 1.5],\n",
       "       [4.5, 1.3],\n",
       "       [4.7, 1.6],\n",
       "       [3.3, 1. ],\n",
       "       [4.6, 1.3],\n",
       "       [3.9, 1.4],\n",
       "       [3.5, 1. ],\n",
       "       [4.2, 1.5],\n",
       "       [4. , 1. ],\n",
       "       [4.7, 1.4],\n",
       "       [3.6, 1.3],\n",
       "       [4.4, 1.4],\n",
       "       [4.5, 1.5],\n",
       "       [4.1, 1. ],\n",
       "       [4.5, 1.5],\n",
       "       [3.9, 1.1],\n",
       "       [4.8, 1.8],\n",
       "       [4. , 1.3],\n",
       "       [4.9, 1.5],\n",
       "       [4.7, 1.2],\n",
       "       [4.3, 1.3],\n",
       "       [4.4, 1.4],\n",
       "       [4.8, 1.4],\n",
       "       [5. , 1.7],\n",
       "       [4.5, 1.5],\n",
       "       [3.5, 1. ],\n",
       "       [3.8, 1.1],\n",
       "       [3.7, 1. ],\n",
       "       [3.9, 1.2],\n",
       "       [5.1, 1.6],\n",
       "       [4.5, 1.5],\n",
       "       [4.5, 1.6],\n",
       "       [4.7, 1.5],\n",
       "       [4.4, 1.3],\n",
       "       [4.1, 1.3],\n",
       "       [4. , 1.3],\n",
       "       [4.4, 1.2],\n",
       "       [4.6, 1.4],\n",
       "       [4. , 1.2],\n",
       "       [3.3, 1. ],\n",
       "       [4.2, 1.3],\n",
       "       [4.2, 1.2],\n",
       "       [4.2, 1.3],\n",
       "       [4.3, 1.3],\n",
       "       [3. , 1.1],\n",
       "       [4.1, 1.3],\n",
       "       [6. , 2.5],\n",
       "       [5.1, 1.9],\n",
       "       [5.9, 2.1],\n",
       "       [5.6, 1.8],\n",
       "       [5.8, 2.2],\n",
       "       [6.6, 2.1],\n",
       "       [4.5, 1.7],\n",
       "       [6.3, 1.8],\n",
       "       [5.8, 1.8],\n",
       "       [6.1, 2.5],\n",
       "       [5.1, 2. ],\n",
       "       [5.3, 1.9],\n",
       "       [5.5, 2.1],\n",
       "       [5. , 2. ],\n",
       "       [5.1, 2.4],\n",
       "       [5.3, 2.3],\n",
       "       [5.5, 1.8],\n",
       "       [6.7, 2.2],\n",
       "       [6.9, 2.3],\n",
       "       [5. , 1.5],\n",
       "       [5.7, 2.3],\n",
       "       [4.9, 2. ],\n",
       "       [6.7, 2. ],\n",
       "       [4.9, 1.8],\n",
       "       [5.7, 2.1],\n",
       "       [6. , 1.8],\n",
       "       [4.8, 1.8],\n",
       "       [4.9, 1.8],\n",
       "       [5.6, 2.1],\n",
       "       [5.8, 1.6],\n",
       "       [6.1, 1.9],\n",
       "       [6.4, 2. ],\n",
       "       [5.6, 2.2],\n",
       "       [5.1, 1.5],\n",
       "       [5.6, 1.4],\n",
       "       [6.1, 2.3],\n",
       "       [5.6, 2.4],\n",
       "       [5.5, 1.8],\n",
       "       [4.8, 1.8],\n",
       "       [5.4, 2.1],\n",
       "       [5.6, 2.4],\n",
       "       [5.1, 2.3],\n",
       "       [5.1, 1.9],\n",
       "       [5.9, 2.3],\n",
       "       [5.7, 2.5],\n",
       "       [5.2, 2.3],\n",
       "       [5. , 1.9],\n",
       "       [5.2, 2. ],\n",
       "       [5.4, 2.3],\n",
       "       [5.1, 1.8]])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "a2c19f27",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style>#sk-container-id-1 {color: black;background-color: white;}#sk-container-id-1 pre{padding: 0;}#sk-container-id-1 div.sk-toggleable {background-color: white;}#sk-container-id-1 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-1 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-1 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-1 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-1 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-1 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-1 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-1 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-1 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;}#sk-container-id-1 div.sk-estimator {font-family: monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;}#sk-container-id-1 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-1 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-1 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 div.sk-serial::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: 0;}#sk-container-id-1 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-container-id-1 div.sk-item {position: relative;z-index: 1;}#sk-container-id-1 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-1 div.sk-item::before, #sk-container-id-1 div.sk-parallel-item::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: -1;}#sk-container-id-1 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-1 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-1 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-1 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-1 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-1 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-1 div.sk-label-container {text-align: center;}#sk-container-id-1 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set `[hidden] { display: none !important; }` so we also need the `!important` here to be able to override the default hidden behavior on the sphinx rendered scikit-learn.org. See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;}#sk-container-id-1 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container-id-1\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>KMeans(n_clusters=3)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-1\" type=\"checkbox\" checked><label for=\"sk-estimator-id-1\" class=\"sk-toggleable__label sk-toggleable__label-arrow\">KMeans</label><div class=\"sk-toggleable__content\"><pre>KMeans(n_clusters=3)</pre></div></div></div></div></div>"
      ],
      "text/plain": [
       "KMeans(n_clusters=3)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "estimator = KMeans(n_clusters=3)#构造聚类器\n",
    "estimator.fit(X)#聚类"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "b0c43474",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "X:\\anaconda310\\lib\\site-packages\\sklearn\\cluster\\_kmeans.py:1305: RuntimeWarning: Explicit initial center position passed: performing only one init in KMeans instead of n_init=10.\n",
      "  super()._check_params(X)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<style>#sk-container-id-3 {color: black;background-color: white;}#sk-container-id-3 pre{padding: 0;}#sk-container-id-3 div.sk-toggleable {background-color: white;}#sk-container-id-3 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-3 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-3 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-3 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-3 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-3 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-3 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-3 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-3 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-3 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-3 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;}#sk-container-id-3 div.sk-estimator {font-family: monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;}#sk-container-id-3 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-3 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-3 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-3 div.sk-serial::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: 0;}#sk-container-id-3 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-container-id-3 div.sk-item {position: relative;z-index: 1;}#sk-container-id-3 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-3 div.sk-item::before, #sk-container-id-3 div.sk-parallel-item::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: -1;}#sk-container-id-3 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-3 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-3 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-3 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-3 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-3 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-3 div.sk-label-container {text-align: center;}#sk-container-id-3 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set `[hidden] { display: none !important; }` so we also need the `!important` here to be able to override the default hidden behavior on the sphinx rendered scikit-learn.org. See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;}#sk-container-id-3 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container-id-3\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>KMeans(init=array([[0., 0.],\n",
       "       [3., 7.]]), n_clusters=2)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-3\" type=\"checkbox\" checked><label for=\"sk-estimator-id-3\" class=\"sk-toggleable__label sk-toggleable__label-arrow\">KMeans</label><div class=\"sk-toggleable__content\"><pre>KMeans(init=array([[0., 0.],\n",
       "       [3., 7.]]), n_clusters=2)</pre></div></div></div></div></div>"
      ],
      "text/plain": [
       "KMeans(init=array([[0., 0.],\n",
       "       [3., 7.]]), n_clusters=2)"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y = np.linspace(0,7,8)\n",
    "x = [0,0.5,2.5,3]\n",
    "# x,y=np.meshgrid(x,y)\n",
    "# x,y\n",
    "data = np.array(np.meshgrid(x,y)).T.reshape(-1,2)\n",
    "data\n",
    "init = np.array([data[0],data[-1]])\n",
    "init\n",
    "data\n",
    "kmean = KMeans(n_clusters=2,init = init)\n",
    "kmean.fit(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "18d80cac",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
       "       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
       "       1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\n",
       "       2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 2, 2, 2, 2, 2, 0, 2, 2, 2, 2,\n",
       "       2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0,\n",
       "       0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0,\n",
       "       0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "label_pred = estimator.labels_# 获取聚类的标签\n",
    "label_pred"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "b85edbf3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png":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BcEFJH+AL4O4DZb5wlS2SIREaXGIRciopBgQiciCgkmdCKikGBCJyIKCSZ0IqKQYEInIgoJJnQiopD4P/o3XHYxsRPmAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 绘制 Kmeans的结果\n",
    "x0 = X[label_pred == 0]\n",
    "x1 = X[label_pred == 1]\n",
    "x2 = X[label_pred == 2]\n",
    "\n",
    "target_names=['label1','label2','label3']\n",
    "for c,m,i,target_name in zip('rgb','o*+',[0,1,2],target_names):\n",
    "    plt.scatter(X[label_pred==i,0],X[label_pred==i,1],color=c,marker=m,label=target_name)\n",
    "\n",
    "plt.legend()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bef59fe9",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "03f47a50",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bd06d8b4",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b04f938a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "43813127",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "43833dd4",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b82e75c5",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4ca08dd8",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5f0408dd",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6ebfdaa4",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9a7f6f32",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "b674862d",
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "from sklearn.cluster import KMeans\n",
    "import numpy as np\n",
    "X = np.array([[1, 2], [1, 4], [1, 0],\n",
    "              [10, 2], [10, 4], [10, 0]])\n",
    "kmeans = KMeans(n_clusters=3, random_state=0).fit(X)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "08f2cd71",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['X:\\\\jupyter\\\\数据结构\\\\机器学习',\n",
       " 'X:\\\\anaconda310\\\\python39.zip',\n",
       " 'X:\\\\anaconda310\\\\DLLs',\n",
       " 'X:\\\\anaconda310\\\\lib',\n",
       " 'X:\\\\anaconda310',\n",
       " '',\n",
       " 'C:\\\\Users\\\\86183\\\\AppData\\\\Roaming\\\\Python\\\\Python39\\\\site-packages',\n",
       " 'X:\\\\anaconda310\\\\lib\\\\site-packages',\n",
       " 'X:\\\\anaconda310\\\\lib\\\\site-packages\\\\locket-0.2.1-py3.9.egg',\n",
       " 'X:\\\\anaconda310\\\\lib\\\\site-packages\\\\win32',\n",
       " 'X:\\\\anaconda310\\\\lib\\\\site-packages\\\\win32\\\\lib',\n",
       " 'X:\\\\anaconda310\\\\lib\\\\site-packages\\\\Pythonwin',\n",
       " 'X:\\\\anaconda310\\\\lib\\\\site-packages\\\\IPython\\\\extensions',\n",
       " 'C:\\\\Users\\\\86183\\\\.ipython',\n",
       " 'X:\\\\python310\\\\Lib\\\\site-packages',\n",
       " 'X:\\\\python310\\\\Lib\\\\site-packages']"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import sys\n",
    "sys.path.append('X:\\\\python310\\\\Lib\\\\site-packages')\n",
    "sys.path"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "72930a4d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['X:\\\\jupyter\\\\数据结构\\\\机器学习',\n",
       " 'X:\\\\anaconda310\\\\python39.zip',\n",
       " 'X:\\\\anaconda310\\\\DLLs',\n",
       " 'X:\\\\anaconda310\\\\lib',\n",
       " 'X:\\\\anaconda310',\n",
       " '',\n",
       " 'C:\\\\Users\\\\86183\\\\AppData\\\\Roaming\\\\Python\\\\Python39\\\\site-packages',\n",
       " 'X:\\\\anaconda310\\\\lib\\\\site-packages',\n",
       " 'X:\\\\anaconda310\\\\lib\\\\site-packages\\\\locket-0.2.1-py3.9.egg',\n",
       " 'X:\\\\anaconda310\\\\lib\\\\site-packages\\\\win32',\n",
       " 'X:\\\\anaconda310\\\\lib\\\\site-packages\\\\win32\\\\lib',\n",
       " 'X:\\\\anaconda310\\\\lib\\\\site-packages\\\\Pythonwin',\n",
       " 'X:\\\\anaconda310\\\\lib\\\\site-packages\\\\IPython\\\\extensions',\n",
       " 'C:\\\\Users\\\\86183\\\\.ipython',\n",
       " 'X:\\\\python310\\\\Lib\\\\site-packages',\n",
       " 'X:\\\\python310\\\\Lib\\\\site-packages']"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import sys\n",
    "sys.path"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "16d974a5",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c1c51698",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c28a4d7f",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9f03be21",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
